<?php
/**
 * Description of d
 *
 * @author Shermor
 */
 class Login extends Controller {

		 function index()
		 {
				 	if (isset($_POST['uname']) && isset($_POST['pword']))
					{
							$this->form_validation->set_rules('uname', 'User Name', 'required|trim|xss_clean|alpha_numeric');
							$this->form_validation->set_rules('pword', 'Password', 'required|trim|xss_clean');

							
						if ($this->form_validation->run() == FALSE)
							{
							 $data['title'] = "L & R Veterinarian Clinic";
                                                                                                              
                                                       $this->load->view('login/index', $data);
                                                       
							
							}
						else
							{
								$username = $_POST['uname'];
								$password = $_POST['pword'];
								$userslist = $this->users_info->login($username);
							
								if(empty($userslist))
								{
								echo "Incorrect username";
								 $data['title'] = "L & R Veterinarian Clinic";
                                                                $this->load->view('header', $data);
                                                               $this->load->view('menu');
                                                               $this->load->view('login/index', $data);
                                                               $this->load->view('footer');
								}
								else {
								foreach($userslist as $key => $object)
								{				
								if($password == $object->password)
								{									
								$permission = element('permissions_1', $userslist);
								
								
								$array_user = array (
										'username' => $username, 'permission' => $object->permissions_1);
								
								$this->session->set_userdata($array_user);
								 $session_user = $this->session->userdata('username');
								 $session_permission = $this->session->userdata('permission');

								$data['user'] = $session_user;
								$data['permission'] = $session_permission;
								 $data['title'] = "L & R Veterinarian Clinic";
                                                             
                                                                $this->load->view('login/welcome', $data);

								}
								else{
                                                                 $data['title'] = "L & R Veterinarian Clinic";
                                                                 
                                                                 $this->load->view('login/index', $data);
								
								}
                                                                }
								}
						}
					}
					else{
						       $data['title'] = "L & R Veterinarian Clinic";
                                                       
                                                       $this->load->view('login/index', $data);
					}
		 }
		 function welcome(){
				 $session_user = $this->session->userdata('username');
				
				if(strlen(!$session_user == 0))
					{
					$data['user'] = $session_user;

					$session_permission = $this->session->userdata('permission');

							$data['permission'] = $session_permission;
                                         $data['title'] = "L & R Veterinarian Clinic";
                                            $this->load->view('header', $data);
                                           $this->load->view('menu');
                                           $this->load->view('login/welcome', $data);
                                           $this->load->view('footer');
					}
					else
					{
					 $data['title'] = "L & R Veterinarian Clinic";
                                         $this->load->view('header', $data);
                                         $this->load->view('menu');
                                         $this->load->view('login/index', $data);
                                         $this->load->view('footer');
					}
		 }
		
 }
